package com.gcorp.idealgas;

public class Vector2
{
    private float x;
    
    private float y;
    
    public float getX()
    {
        return x;
    }
    public float getY()
    {
        return y;
    }
    
    public Vector2(float x, float y)
    {
        this.x = x;
        this.y = y;
    }
    public void set(float x,float y)
    {
        this.x = x;
        this.y = y;
    }
    public void set(Vector2 v)
    {
        set(v.getX(),v.getY());
    }
    public Vector2 sub(Vector2 v)
    {
        
        return new Vector2(this.x - v.getX(),this.y - v.getY());
    }
    public void add(Vector2 v)
    {
        this.x += v.getX();
        this.y += v.getY();
    }
    public float scalarProduct(Vector2 v)
    {
        return this.x * v.getX() + this.y * v.getY();
    }
    public Vector2 mulOnScalar(float scalar)
    {
        return new Vector2(this.x * scalar, this.y * scalar);
    }

    public void normalize()
    {
        float inv_len = 1.0f / (float)Math.sqrt(x*x+y*y);
        
        this.x = x * inv_len;
        this.y = y * inv_len;
    }
    public void incX(float x)
    {
    	this.x += x;
    }
    public void incY(float y)
    {
    	this.y += y;
    }

    
    
    public void setX(float x)
    {
        this.x = x;
    }
    public void setY(float y)
    {
        this.y = y;
    }
    public Vector2 reverseX()
    {
        return new Vector2(-this.x,this.y);
    }
    public float getAngleWith(Vector2 v2)
    {
        float c1 = x + v2.getX();
        float c2 = y + v2.getY();
        
        float m1 = (float) Math.sqrt(x*x + y*y);
        float m2 = (float) Math.sqrt(v2.getX()*v2.getX() + v2.getY()*v2.getY());
        
        return (float) (Math.cos((c1*c2)/(m1*m2)) * 180 / Math.PI);
    }
    public float getMagnitude()
    {
        return (float) Math.sqrt(x*x + y*y);
    }
}